#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
#include "ti.h"
#include "tplate.h"

using namespace std;

void read_image_cont(float** ti, char* file, int& length, int& width, int& NR_variable)
{
    //read multiband tiff as the training image.
    GDALDataset* poDS;
    GDALAllRegister();
    poDS = (GDALDataset*)GDALOpen(file, GA_ReadOnly);
    if (poDS == NULL) {
        cout << "Raster file open failed." << endl;
        exit(1);
    }
    width = poDS->GetRasterXSize();
    length = poDS->GetRasterYSize();
    NR_variable = poDS->GetRasterCount();
    int size = width * length * NR_variable;
    *ti = new float[size];
    GDALRasterBand* poBand;
    for (int i = 1; i <= NR_variable; i++) {
        poBand = poDS->GetRasterBand(i);
        poBand->RasterIO(GF_Read, 0, 0, width, length, (*ti) + (i - 1) * width * length, width, length, GDT_Float32, 0, 0);
    }
    return;
}
